/*
 * Copyright 2010-2012, David George, Licensed under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.magneato.dto;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * Used for registration, extends basic spring functionality
 * 
 * @author David George
 */
public class MagUser implements UserDetails {
	private static final long serialVersionUID = 7402746293711442541L;
	private int id;
	private String username;
	private String screenName;
	private String password;
	
	private boolean enabled;

	Collection<? extends GrantedAuthority> authorities;

	private long joinDate;

	// additional registration details
	private String passwordConfirmation;
	private String oldPassword;
	private boolean acceptTerms = false;
	private String referer;
	private String ip;
	
	public static final String dateFormat="dd MMM yyyy";

	public MagUser() {
		username = "";
		screenName = "";
	}

	public MagUser(String username, String password, boolean enabled,
			Collection<? extends GrantedAuthority> authorities) {
		this.username = username;
		this.password = password;
		this.enabled = enabled;
		this.authorities = authorities;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getScreenname() {
		return screenName;
	}

	public void setScreenname(String screenName) {
		this.screenName = screenName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Collection<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getReferer() {
		return referer;
	}

	public void setReferer(String referer) {
		this.referer = referer;
	}

	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}

	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}
	
	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public boolean isAcceptTerms() {
		return acceptTerms;
	}

	public void setAcceptTerms(boolean acceptTerms) {
		this.acceptTerms = acceptTerms;
	}

	public void setJoinDate(long joinDate) {
		this.joinDate = joinDate;
	}

	public long getJoinDate() {
		return joinDate;
	}
	
	/*
	 * Return in the format 
	 */
	public String getJoinDateString() {
	    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        return sdf.format( new Date(joinDate) );
	}

	@Override
	public String toString() {
		return "MagUser [username=" + username + ", screenName=" + screenName
				+ ", password=" + password + ", joinDate=" + joinDate
				+ ", oldPassword=" + oldPassword + ", ip=" + ip + ", id="
				+ id + "]";
	}

	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}

	
}
